package me.lijf.xapi.config;

import me.lijf.xapi.dynamic.TableNameInterceptor;
import me.lijf.xapi.security.AuthInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class InterceptorConfig extends WebMvcConfigurerAdapter {
    @Bean
    public AuthInterceptor authInterceptor(){
        return new AuthInterceptor();
    }
    @Bean
    public TableNameInterceptor tableNameInterceptor(){
        return new TableNameInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(
                    authInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(new String[]{"/swagger-ui/**","/swagger-resources/**", "/v3/**"})
                .excludePathPatterns(new String[]{ "/error"})
        ;
        registry.addInterceptor(
                    tableNameInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(new String[]{"/swagger-ui/**","/swagger-resources/**", "/v3/**"})
                .excludePathPatterns(new String[]{ "/error"})
        ;
        super.addInterceptors(registry);
    }
}
